<template>
  <router-layout>
    <div class="lackyDraw">
      <div class="list">
        <!-- 暂无数据组件 -->
        <Nodata v-if="isNoData"></Nodata>
        <van-list v-else v-model="loading" :finished="finished" @load="onLoad" :offset="0">
          <van-cell v-for="item in activeDataList" :key="item.id">
            <div class="lacky-list" @click="openLink(item)">
              <van-row type="flex" al>
                <van-col>
                  <div class="list-img">
                    <img :src="item.file_path" width="100%" alt>
                  </div>
                </van-col>
                <van-col>
                  <div class="list-right">
                    <div class="right-header fn-clear">{{ item.questionnaire_title }}</div>
                    <div class="right-time">内容简介:{{ item.questionnaire_desc | text }}</div>
                    <div class="base">
                      <p class="base-text">创建时间：{{ item.create_time | formate_date }}</p>
                    </div>
                  </div>
                </van-col>
              </van-row>
            </div>
          </van-cell>
        </van-list>
      </div>
    </div>
  </router-layout>
</template>
<script>
import { servey_listMyPartake } from "@/api/survey";
import Nodata from "../public/nodata/Nodata"; // 导入暂无数据组件
import moment from "moment";
import TitleItem from "../../components/public/title/title";

export default {
  name: "SurveyPartake",
  components: { Nodata, TitleItem },
  computed: {
    activeDataList: function () {
      return this.dataList.filter(function (item) {
        return item.close_status == 1
      })
    }
  },
  data() {
    return {
      dataList: [],
      staus: 1,
      isNoData: false,
      loading: false,
      finished: false,
      listQuery: {
        current: 1,
        limit: 5,
        company_id: localStorage.getItem("companyId") || 1
      },
      total: ""
    };
  },
  filters: {
    formate_date(v) {
      return moment(v).format("YYYY/MM/DD");
    }
  },
  methods: {
    openLink(e) {
      this.$router.push({
        path: "/SurveyDetails",
        query: { id: e.id, status: e.active_status, name: "home" }
      });
    },
    async initList() {
      let res = await servey_listMyPartake(this.listQuery);
      if (res.data.status == 100) {
        this.dataList = res.data.data.rows;
        this.total = res.data.data.results;
        if (!this.total) {
          this.isNoData = true;
        }
      }
      this.loading = false;
      if (res.data.data.results <= this.dataList.length) {
        this.finished = true;
      }
    },
    onLoad() {
      setTimeout(() => {
        this.listQuery.limit += 2;
        this.initList();
      }, 1000);
    }
  },
  created: function() {
    this.initList();
  }
};
</script>
<style lang="scss" scoped>
@import "SurveryList";
</style>
